package com.example.yls.listview_sqlite;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class EditActivity extends AppCompatActivity {
    private EditText edtStuno;
    private EditText edtStuname;
    private EditText edtStuage;
    private Button btnSave;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_edit);


        edtStuage = findViewById(R.id.edt_Stuage);
        edtStuname = findViewById(R.id.edt_Stuname);
        edtStuno = findViewById(R.id.edt_Stuno);
        btnSave = findViewById(R.id.btn_save);

        btnSave.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent();
                intent.putExtra("STUNO",edtStuno.getText().toString());
                intent.putExtra("NAME",edtStuname.getText().toString());
                intent.putExtra("AGE",Integer.parseInt(edtStuage.getText().toString()));
                setResult(3001,intent);
                finish();


            }
        });
        String stuno = getIntent().getStringExtra("STUNO");
        String stuname = getIntent().getStringExtra("NAME");
        int stuage = getIntent().getIntExtra("AGE",0);

        edtStuno.setText(stuno);
        edtStuname.setText(stuname);
        edtStuage.setText(String.valueOf(stuage));
    }
}
